package br.com.canvasForAll.ws.resource;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.EJB;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import br.com.canvasForAll.model.entity.Canvas;
import br.com.canvasForAll.model.entity.Comentario;
import br.com.canvasForAll.model.entity.Perfil;
import br.com.canvasForAll.model.entity.Postit;
import br.com.canvasForAll.model.repository.CanvasRepository;
import br.com.canvasForAll.model.repository.PerfilRepository;
import br.com.canvasForAll.model.repository.PostitRepository;
import br.com.canvasForAll.model.services.interfaces.ComentarioService;

@Path("port")
public class PortWS {

	@EJB private PostitRepository postitRepository;
	@EJB private PerfilRepository perfilRepository;
	@EJB private CanvasRepository canvasRepository;
	@EJB private ComentarioService comentarioService;
	
//	@GET
//	@Produces(MediaType.APPLICATION_JSON)
//	public List<Postit> buscarPostIts() throws Exception {
//		return postitRepository.obterTodos();
//
//	}
	
	@GET
	@Produces(MediaType.APPLICATION_JSON)
	public List<Map<Postit, List<Comentario>>> buscarPostIts() throws Exception {
		List<Map<Postit, List<Comentario>>> result = new ArrayList<>();
		
		for(Postit p : postitRepository.obterTodos()){
			List<Comentario> comentarios = (List<Comentario>) comentarioService.obterComentarioPorPostit(p);
			Map<Postit, List<Comentario>> map = new HashMap<>();
			map.put(p, comentarios);
			result.add(map);
		}
		
		return result;
	}
	
	@GET
	@Path("{responsavel}")
	@Produces(MediaType.APPLICATION_JSON)
	public List<Canvas> responsavelCanvas(@PathParam("responsavel") Long responsavel) throws Exception {
		Perfil p = perfilRepository.obterId(new Long(responsavel));
//		List<Canvas> canvasResponsavel = canvasRepository.obterCanvasPorResponsavel(p);
		
//		return canvasResponsavel;
		return null;
		
	}
	
}
